﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Client.Services;
using CrmField.Plugins;
using System.Collections.Generic;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.Linq;

namespace CrmField.Tests.Plugins
{
    [TestClass]
    public class ClientChannelManagerTest
    {
        [TestMethod]
        public void RetrieveUsersInServiceAppointment()
        {
            CrmConnection crmConnection = new CrmConnection("devCrmOnline");
            var service = new OrganizationService(crmConnection);

            EntityCollection users = service.RetrieveMultiple(new QueryExpression("systemuser"));
            if(users.Entities.Count >0)
            {
                List<Guid> userList = new List<Guid>(users.Entities.Count);
                users.Entities.ToList().ForEach((e) => userList.Add(e.Id));

                Dictionary<Guid,string> usersChannel = ClientChannelManager.RetrieveLatestUsersChannel(userList, service);
            }
        }
    }
}
